﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using IndicoInterface;
using DeeptalkConverterLib;

namespace DeepTalkConverterSA.App
{
    /// <summary>
    /// Run the conversion program from the command-line
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Usage: <xmlfilewithagendaxml> <outputdir>");
                    return;
                }

                string xmlFile = args[0];
                string outputDirText = args[1];

                ///
                /// Process the directory
                /// 

                DirectoryInfo outputDir = new DirectoryInfo(outputDirText);
                if (!outputDir.Exists)
                {
                    Console.WriteLine("Directory " + outputDir.FullName + " does not exist!");
                    return;
                }

                ///
                /// And now the agenda XML
                /// 

                AgendaInfo ai = null;
                using (var reader = File.OpenText(xmlFile))
                {
                    string xml = reader.ReadToEnd();
                    ai = AgendaInfo.Deseralize(xml);
                }

                Console.WriteLine("Processing agenda at " + ai.AgendaSite + " with ID=" + ai.ConferenceID + " (subdir: " + ai.AgendaSubDirectory + ")");

                RenderControl rc = new RenderControl();
                rc.StartRender(ai, outputDir);
                rc.WaitForDone();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed while trying to process agenda!");
                Console.WriteLine("Error Message: " + e.Message);
                Console.WriteLine("Stack trace: " + e.StackTrace);
            }
        }
    }
}
